package com.upb.webserver.common.tools.encryption.sm2;

import java.math.BigInteger;

import org.bouncycastle.math.ec.ECPoint;

import com.upb.webserver.common.tools.encryption.HexUtil;

import lombok.Getter;

/**
 *
 */

@Getter
public class SM2KeyPair {

    private ECPoint publicKeyECPoint;
    private BigInteger privateKey;

    private SM2KeyPair(){}

    public static SM2KeyPair newInstance(
            BigInteger privateKey,
            ECPoint publicKey) {
        SM2KeyPair keyPair = new SM2KeyPair();
        keyPair.publicKeyECPoint = publicKey;
        keyPair.privateKey = privateKey;
        return keyPair;
    }

    /**
     *
     * @return
     */
    public String ecPointToHex(){
        return HexUtil.byteToHexUpper(publicKeyECPoint.getEncoded(false));
    }

    /**
     *
     * @return
     */
    public String privateToHex() {
        return HexUtil.byteToHexUpper(privateKey.toByteArray());
    }
}